import { expect, test } from 'vitest'

import { getApprovalBasedPaymasterInput } from './getApprovalBasedPaymasterInput.js'

test('args: token, minAllowance and innerInput as hex', () => {
  expect(
    getApprovalBasedPaymasterInput({
      innerInput: '0x',
      minAllowance: 1n,
      token: '0x65C899B5fb8Eb9ae4da51D67E1fc417c7CB7e964',
    }),
  ).toEqual(
    '0x949431dc00000000000000000000000065c899b5fb8eb9ae4da51d67e1fc417c7cb7e964000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000',
  )

  expect(
    getApprovalBasedPaymasterInput({
      innerInput: '0x000102030405',
      minAllowance: 2n,
      token: '0x65C899B5fb8Eb9ae4da51D67E1fc417c7CB7e964',
    }),
  ).toEqual(
    '0x949431dc00000000000000000000000065c899b5fb8eb9ae4da51d67e1fc417c7cb7e9640000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000060001020304050000000000000000000000000000000000000000000000000000',
  )
})

test('args: token, minAllowance and innerInput as byte array', () => {
  expect(
    getApprovalBasedPaymasterInput({
      innerInput: new Uint8Array(),
      minAllowance: 1n,
      token: '0x65C899B5fb8Eb9ae4da51D67E1fc417c7CB7e964',
    }),
  ).toEqual(
    '0x949431dc00000000000000000000000065c899b5fb8eb9ae4da51d67e1fc417c7cb7e964000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000',
  )

  expect(
    getApprovalBasedPaymasterInput({
      innerInput: new Uint8Array([0, 1, 2, 3, 4, 5]),
      minAllowance: 2n,
      token: '0x65C899B5fb8Eb9ae4da51D67E1fc417c7CB7e964',
    }),
  ).toEqual(
    '0x949431dc00000000000000000000000065c899b5fb8eb9ae4da51d67e1fc417c7cb7e9640000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000060001020304050000000000000000000000000000000000000000000000000000',
  )
})
